package dbVSguiConnection;

import gui.Main;


import java.util.ArrayList;

import runnable_functions.*;



import details.*;


public class GuiCallDb implements GuiCallDb_Interface {

	private static SEARCHfunctions search = new SEARCHfunctions();
	private static USERfunctions user = new USERfunctions();
	private static DELETEfunctions delete = new DELETEfunctions();
	private static ADDfunctions add = new ADDfunctions();
	private static EDITfunctions edit = new EDITfunctions();
	private static GETfunctions get = new GETfunctions();
	
	
	public Thread thread  =null;

	@Override
	public void goToHome() {
		
		(new Thread(get.new GetTop5(Main.signal))).start();
		

	}
	
	@Override
	public void getArtistSearchResults(String name,int numOfResults) {
		(new Thread(search.new GetArtistSearchResults(name,numOfResults,Main.signal))).start();

	}
	
	@Override
	public void getAdvanceCdSearchResults(String titleToSearch,
			String performerToSearch, String genreToSearch,int yearFrom, int yearTo,
			int numOfResults) {
		(new Thread(search.new GetAdvancedCdSearchResults(titleToSearch,performerToSearch,genreToSearch,yearFrom,yearTo,numOfResults,Main.signal))).start();
		
	}

	@Override
	public void getAdvanceSongSearchReasults(String titleToSearch,
			String artistToSearch, String wordsToSearch, int numOfResults) {
		(new Thread(search.new GetAdvancedSongSearchResults(titleToSearch,artistToSearch,wordsToSearch,numOfResults,Main.signal))).start();
		
	}

//	@Override
//	public void getYearRangeCdSearchResult(int yearFromSearch,
//			int yearToSearch, int numOfResults) {
//		(new Thread(search.new GetYearRangeCdSearchResults(yearFromSearch ,yearToSearch,numOfResults,Main.signal))).start();
//		
//	}

	@Override
	public void getArtistAllInfo(int artist_id) {
		(new Thread(search.new GetByIdSearchResults(Integer.toString(artist_id),ReferedObject.ARTIST,Main.signal))).start();

	}

	@Override
	public void getSongAllInfo(int songId) {
		(new Thread(search.new GetByIdSearchResults(Integer.toString(songId),ReferedObject.SONG,Main.signal))).start();
	}
	/* from lyric database not from our*/
	public void getSongLyrics(Song song){
		(new Thread(search.new GetSongLyric(song,Main.signal))).start();
	}
	
	/* TODO when the dialog calls it we have to write new C...(2)*/
	@Override
	public void getCdAllInfo(Cd cd) {
		(new Thread(search.new GetByIdSearchResults(cd.getAlbom_id(),ReferedObject.CD,Main.signal))).start();
		(new Thread(search.new GetCdCover(cd.getPerformer(),cd.getTitle(),Main.signal))).start();

	}

	
	@Override
	public void createNewUser(String user_name, String password) {
		(new Thread(user.new MakeNewUser(user_name,password,Main.signal))).start();

	}

	@Override
	public void logIn(String user_name, String password) {
		(new Thread(user.new LogInUser(user_name,password,Main.signal))).start();

	}


	@Override
	public void deleteUser(String user_name, String password,User curr_user) {
		(new Thread(user.new DeleteUser(user_name,password,curr_user,Main.signal))).start();

	}

	@Override
	public void changePassword(String user_name, String oldPass, String newPass) {
		(new Thread(user.new ChangePassword(user_name,oldPass,newPass,Main.signal))).start();

	}

	@Override
	public void delete(ReferedObject objType, String identifier,String username) {
		(new Thread(delete.new Delete(identifier,objType,username,Main.signal))).start();
	}

	@Override
	public void deleteCommentSong(User user,Comment comment,int song_id) {
		(new Thread(delete.new DeleteComment(comment,user,song_id,Main.signal))).start();

	}

	@Override
	//(String cd_name,String genre,String performer,int releaseYear,ArrayList<Track> tracks
	public void addCd(String cd_name, String genre, String performer, int releaseYear, ArrayList<Track> tracks) {
		(new Thread(add.new AddNewCd(cd_name, performer, genre, releaseYear, tracks,Main.signal))).start();

	}
	/* edit song track cd....to add*//* delete all tracks of cdand ad  new one in cse its different*/

	@Override
	public void addLyricToSong(String content, int song_id,String curr_user) {
		(new Thread(edit.new Edit(Integer.toString(song_id),ReferedObject.LYRIC,curr_user, content,Main.signal))).start();

	}

	@Override
	public void addCommenToSong(User user, String comment, String DATETIME,int song_id) {
		(new Thread(add.new AddSongComment(comment, song_id, user, DATETIME,Main.signal))).start();
	}

	@Override
	public void like_unlike(Target target, String target_id, User user,Like l) {
		switch(l){
		case LIKE:
			(new Thread(add.new Like(user, target,target_id,Main.signal ))).start();
			break;
		
		case UNLIKE:
			
			(new Thread(delete.new Unlike(user, target,target_id,Main.signal ))).start();
			break;
		default:
			break;
		}
	}

	@Override
	public void updateDB(String update_file_name) {/* update_file_name is the full path */
		(new Thread (new UpdateFreeDB(update_file_name,Main.signal))).start();

	}

	@Override
	public void editCd(String cd_id,String changed_name,int changed_cdYear,String changed_performer,ArrayList<Track> changedCdTracks,String curr_user) {
		((new Thread(edit.new EditCd(cd_id,changed_name,changed_cdYear, changed_performer,changedCdTracks,curr_user,Main.signal)))).start();
		
	}
	@Override
	public void editRest(String identifier,ReferedObject refObj,String changed_name,String curr_user){
		(new Thread(edit.new Edit(identifier,refObj, changed_name,curr_user,Main.signal))).start();
	}

	@Override
	public void deleteEmptyCds() {
		(new Thread(delete.new DeleteEmptyCds(Main.signal))).start();
		
	}

	@Override
	public void connectToDataBase() {
		(new Thread(new ConnectDB(Main.signal))).start();
	}

	@Override
	public void getIfUserLike(Target target, String target_id, int user_id) {
		(new Thread(get.new IsUserLike(target_id, target, user_id, Main.signal))).start();
		
	}

	
	

	
	

	

}
